// $ANTLR 3.4 ./src/main/java/hero/antlr2/Simplest.g 2011-12-03 21:48:52
package hero.antlr2;

import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;

import org.antlr.runtime.tree.*;


@SuppressWarnings({"all", "warnings", "unchecked"})
public class SimplestParser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "DOC", "ID", "INT", "NEWLINE", "SHIT", "TITLE", "WS"
    };

    public static final int EOF=-1;
    public static final int DOC=4;
    public static final int ID=5;
    public static final int INT=6;
    public static final int NEWLINE=7;
    public static final int SHIT=8;
    public static final int TITLE=9;
    public static final int WS=10;

    // delegates
    public Parser[] getDelegates() {
        return new Parser[] {};
    }

    // delegators


    public SimplestParser(TokenStream input) {
        this(input, new RecognizerSharedState());
    }
    public SimplestParser(TokenStream input, RecognizerSharedState state) {
        super(input, state);
    }

protected TreeAdaptor adaptor = new CommonTreeAdaptor();

public void setTreeAdaptor(TreeAdaptor adaptor) {
    this.adaptor = adaptor;
}
public TreeAdaptor getTreeAdaptor() {
    return adaptor;
}
    public String[] getTokenNames() { return SimplestParser.tokenNames; }
    public String getGrammarFileName() { return "./src/main/java/hero/antlr2/Simplest.g"; }


    public static class prog_return extends ParserRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "prog"
    // ./src/main/java/hero/antlr2/Simplest.g:17:1: prog : ( stat )+ ;
    public final SimplestParser.prog_return prog() throws RecognitionException {
        SimplestParser.prog_return retval = new SimplestParser.prog_return();
        retval.start = input.LT(1);


        CommonTree root_0 = null;

        SimplestParser.stat_return stat1 =null;



        try {
            // ./src/main/java/hero/antlr2/Simplest.g:17:5: ( ( stat )+ )
            // ./src/main/java/hero/antlr2/Simplest.g:17:9: ( stat )+
            {
            root_0 = (CommonTree)adaptor.nil();


            // ./src/main/java/hero/antlr2/Simplest.g:17:9: ( stat )+
            int cnt1=0;
            loop1:
            do {
                int alt1=2;
                int LA1_0 = input.LA(1);

                if ( ((LA1_0 >= ID && LA1_0 <= INT)) ) {
                    alt1=1;
                }


                switch (alt1) {
            	case 1 :
            	    // ./src/main/java/hero/antlr2/Simplest.g:17:9: stat
            	    {
            	    pushFollow(FOLLOW_stat_in_prog70);
            	    stat1=stat();

            	    state._fsp--;

            	    adaptor.addChild(root_0, stat1.getTree());

            	    }
            	    break;

            	default :
            	    if ( cnt1 >= 1 ) break loop1;
                        EarlyExitException eee =
                            new EarlyExitException(1, input);
                        throw eee;
                }
                cnt1++;
            } while (true);


            }

            retval.stop = input.LT(-1);


            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "prog"


    public static class stat_return extends ParserRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "stat"
    // ./src/main/java/hero/antlr2/Simplest.g:18:1: stat : atom2= atom NEWLINE ;
    public final SimplestParser.stat_return stat() throws RecognitionException {
        SimplestParser.stat_return retval = new SimplestParser.stat_return();
        retval.start = input.LT(1);


        CommonTree root_0 = null;

        Token NEWLINE2=null;
        SimplestParser.atom_return atom2 =null;


        CommonTree NEWLINE2_tree=null;

        try {
            // ./src/main/java/hero/antlr2/Simplest.g:18:5: (atom2= atom NEWLINE )
            // ./src/main/java/hero/antlr2/Simplest.g:18:9: atom2= atom NEWLINE
            {
            root_0 = (CommonTree)adaptor.nil();


            pushFollow(FOLLOW_atom_in_stat82);
            atom2=atom();

            state._fsp--;

            adaptor.addChild(root_0, atom2.getTree());

            NEWLINE2=(Token)match(input,NEWLINE,FOLLOW_NEWLINE_in_stat84); 
            NEWLINE2_tree = 
            (CommonTree)adaptor.create(NEWLINE2)
            ;
            adaptor.addChild(root_0, NEWLINE2_tree);


             System.out.println("atom2 value is " + (atom2!=null?atom2.value:0)); 

            }

            retval.stop = input.LT(-1);


            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "stat"


    public static class atom_return extends ParserRuleReturnScope {
        public int value;
        CommonTree tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "atom"
    // ./src/main/java/hero/antlr2/Simplest.g:22:1: atom returns [int value] : ( INT | ID );
    public final SimplestParser.atom_return atom() throws RecognitionException {
        SimplestParser.atom_return retval = new SimplestParser.atom_return();
        retval.start = input.LT(1);


        CommonTree root_0 = null;

        Token INT3=null;
        Token ID4=null;

        CommonTree INT3_tree=null;
        CommonTree ID4_tree=null;


            System.out.println("init");
          
        try {
            // ./src/main/java/hero/antlr2/Simplest.g:29:3: ( INT | ID )
            int alt2=2;
            int LA2_0 = input.LA(1);

            if ( (LA2_0==INT) ) {
                alt2=1;
            }
            else if ( (LA2_0==ID) ) {
                alt2=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 2, 0, input);

                throw nvae;

            }
            switch (alt2) {
                case 1 :
                    // ./src/main/java/hero/antlr2/Simplest.g:30:5: INT
                    {
                    root_0 = (CommonTree)adaptor.nil();


                    INT3=(Token)match(input,INT,FOLLOW_INT_in_atom121); 
                    INT3_tree = 
                    (CommonTree)adaptor.create(INT3)
                    ;
                    adaptor.addChild(root_0, INT3_tree);


                    retval.value = Integer.parseInt((INT3!=null?INT3.getText():null));

                    }
                    break;
                case 2 :
                    // ./src/main/java/hero/antlr2/Simplest.g:31:9: ID
                    {
                    root_0 = (CommonTree)adaptor.nil();


                    ID4=(Token)match(input,ID,FOLLOW_ID_in_atom133); 
                    ID4_tree = 
                    (CommonTree)adaptor.create(ID4)
                    ;
                    adaptor.addChild(root_0, ID4_tree);


                     System.out.println((ID4!=null?ID4.getText():null)); retval.value = 10; 

                    }
                    break;

            }
            retval.stop = input.LT(-1);


            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);


                System.out.println("after");
              
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "atom"

    // Delegated rules


 

    public static final BitSet FOLLOW_stat_in_prog70 = new BitSet(new long[]{0x0000000000000062L});
    public static final BitSet FOLLOW_atom_in_stat82 = new BitSet(new long[]{0x0000000000000080L});
    public static final BitSet FOLLOW_NEWLINE_in_stat84 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_INT_in_atom121 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_atom133 = new BitSet(new long[]{0x0000000000000002L});

}